from random import random,shuffle,gauss

def default_mutation( indiv, p_min, p_max,p_ro ):
  assert(len(indiv[0])==len(p_min))
  assert(len(indiv[0])==len(p_max))
  assert(len(indiv[0])==len(p_ro))
  if p_ro==None:
    p_ro=[(p_max[i]-p_min[i])/2.0 for i in range(len(indiv[0]))]
  return [[max(min(indiv[0][i]+gauss(0,p_ro[i]),p_max[i]),p_min[i]) for i in range(len(indiv[0]))]]

def default_crossover( p_a, p_b ):
  if random()<0.5:
    return p_a,p_b
  else:
    return p_b,p_a

def default_random( p_min, p_max ):
  assert(len(p_min)==len(p_max))
  return [random()*(p_max[i]-p_min[i])+p_min[i] for i in range(len(p_min))]

